<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>CommonWeb Framework - Introduction</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
          <meta name="author" content="Dave W." />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                    <span id="bannerLeft">
    
            CommonWeb Framework
    
            </span>
                          <span id="bannerRight">
    
            Big-Oh Software ... computer scientists find big-oh!!
    
            </span>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
            
  
    
            <div class="xleft">
        Version: 2.4
              </div>
            <div class="xright">      
  

  
    
            
  
    
             Last Published: 2010-08-08
            </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
            
  
    
                   <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
            
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2>Overview</h2>
<p>The CommonWeb framework offers Servlets, Filters &amp; Liteners to help ease the development of web applications. The frameworks goal is to provide reusable components that can be unobtrusively added to web applications in order to make them more easily understood and maintained.</p>
</div>
<div class="section"><h2>Usage</h2>
<div class="section"><h3>RequestLoggerListener</h3>
<p>Java's web stack is great at abstracting away some of the more mundane HTTP details that underly all web applications. But, a times during development, it can be useful to understand the incoming HTTp requests being made against the server. The RequestLoggerListener is a great tool for logging such requests, increasing their visibility during application development.</p>
<div class="source"><pre>&lt;!-- web.xml snippet --&gt;

&lt;listener&gt;
        &lt;listener-class&gt;net.big_oh.common.web.impl.RequestLoggerListener&lt;/listener-class&gt;
&lt;/listener&gt;</pre>
</div>
<p>After adding the listener to your web.xml as in the example above, you'll notice that HTTP requests are now logged to your console. Here's an example of a logged HTTP request.</p>
<div class="source"><pre>[INFO] RequestLoggerListener - REQUEST  -- START  -- HTTP/1.1 request from localhost (0:0:0:0:0:0:0:1) for resource http://localhost:8080/SandboxWeb/ (GET) --  jSessionId: B47E91D40F85BA1B8B3C8D9A290B69E6 --  userName: unknown

... other statements logged during request processing ...

[INFO] RequestLoggerListener - REQUEST  -- FINISH -- HTTP/1.1 request from localhost (0:0:0:0:0:0:0:1) for resource http://localhost:8080/SandboxWeb/ (GET) --  jSessionId: B47E91D40F85BA1B8B3C8D9A290B69E6 --  userName: unknown</pre>
</div>
</div>
<div class="section"><h3>SimpleSessionTrackingListener</h3>
<p>Lastly, tracking the current users of a deployed web application can provide useful diagnostic info? Running out of heap space on your web server? Are resources exhausted by a misbehaving process? Or perhaps the root cause is too many user sessions? The SimpleSessionTrackingListener can help you detect the later scenario.</p>
<div class="source"><pre>&lt;!-- web.xml snippet --&gt;

&lt;listener&gt;
        &lt;listener-class&gt;net.big_oh.common.web.listener.session.SimpleSessionTrackingListener&lt;/listener-class&gt;
&lt;/listener&gt;</pre>
</div>
<p>Once you've added the SimpleSessionTrackingListener to your web application's deployment descriptor, you can discover information about the currently active HttpSessions in your application.</p>
<div class="source"><pre>// gets a set of all active HttpSession objects for a deployed web application  
SimpleSessionTrackingListener.getSessionsForContext(session.getServletContext())</pre>
</div>
</div>
<div class="section"><h3>ResponseSizeMonitorFilter</h3>
<p>As web applications become richer, the size of the HTTP responses that they generate has tended to increase. Cautious web developers will want to keep a watchful eye on their response sizes, with an eye towards minimizing network utilization.</p>
<div class="source"><pre>&lt;!-- web.xml snippet --&gt;

&lt;filter&gt;
        &lt;filter-name&gt;ResponseSizeMonitorFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;net.big_oh.common.web.impl.ResponseSizeMonitorFilter&lt;/filter-class&gt;
&lt;/filter&gt;

&lt;filter-mapping&gt;
        &lt;filter-name&gt;ResponseSizeMonitorFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;</pre>
</div>
<p>After enabling a filer as in the example above, you'll notice that HTTP response sizes are now logged to your console. Here's an example of a logged HTTP response size.</p>
<div class="source"><pre>[INFO] ResponseSizeMonitorFilter - RESPONSE -- FINISH -- Response for the requested url (http://localhost:8080/SandboxWeb/) contained about 0.51 kilobytes.</pre>
</div>
</div>
<div class="section"><h3>IPAddressFilter</h3>
<p>Filters are a powerful facet of the Servlet specification and can be used to alter, redirect or reject incoming requests. The IPAddressFilter can be deployed in your web application in order to grant or revoke access at the URL level.</p>
<div class="source"><pre>&lt;!-- web.xml snippet --&gt;

&lt;filter&gt;
        &lt;filter-name&gt;IPAddressFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;net.big_oh.common.web.filters.ipaddress.IPAddressFilter&lt;/filter-class&gt;
        &lt;init-param&gt;
                &lt;!-- White list rules take precedence over black list rules.--&gt;
                &lt;param-name&gt;net.big_oh.common.web.filters.ipaddress.ClasslessInterDomainRoutingWhiteListFilterRule&lt;/param-name&gt;
                &lt;param-value&gt;127.0.0.1/32&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
                &lt;param-name&gt;net.big_oh.common.web.filters.ipaddress.ClasslessInterDomainRoutingBlackListFilterRule&lt;/param-name&gt;
                &lt;param-value&gt;
                        127.0.0.1/24
                &lt;/param-value&gt;
        &lt;/init-param&gt;
&lt;/filter&gt;

&lt;filter-mapping&gt;
        &lt;filter-name&gt;IPAddressFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;</pre>
</div>
</div>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2008-2010
    
          Big-Oh Software
          
  

  
    
            
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
